package com.ah.service.impl;

import com.ah.common.R;
import com.ah.request.LoginRequest;
import com.ah.service.IUserService;
import com.ah.utils.JwtUtils;
import com.alibaba.cloud.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements IUserService {
    @Override
    public R login(LoginRequest request){
        // 1、用户名或者密码校验
        if (StringUtils.isEmpty(request.getUsername()) || StringUtils.isEmpty(request.getPassword()) ){
            return R.error("用户名或者密码为空");
        }
        // 2、判断用户名和密码是否正确
        //TODO 数据库操作
        if (request.getUsername().equals("admin")&& request.getPassword().equals("123456")){
            // 颁发登录token
            String token = JwtUtils.sign(1001L, "admin");
            return R.success(token);
        }

        return R.error("用户名或者密码不对");
    }
}
